package com.example.demo.controller;

import com.example.demo.VO.ResultVO;
import com.example.demo.pojo.DeviceEntity;
import com.example.demo.pojo.UserEntity;
import com.example.demo.service.DeviceService;
import com.example.demo.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@RestController
public class DeviceController {

    @Resource
    DeviceService de;


    @GetMapping(value = "/getAllDevice")

    public ResultVO getAllDevice() {

        Map json = new HashMap();
        ResultVO resultVO = new ResultVO();
        List<DeviceEntity> list = de.getAllDevice();
        json.put("deviceList", list);
        resultVO.setData(json);

        return resultVO;
    }

    @PostMapping(value = "/insertDevice")

    public ResultVO insertDevice(@RequestParam(value = "DeviceId", required = true, defaultValue = "") int account,
                                 @RequestParam(value = "DeviceBuyer", required = true, defaultValue = "") String DeviceBuyer,
                                 @RequestParam(value = "DeviceBuyTime", required = true, defaultValue = "") String DeviceBuyTime,
                                 @RequestParam(value = "DevicePlace", required = true, defaultValue = "") String DevicePlace,
                                 @RequestParam(value = "DeviceType", required = true, defaultValue = "") String DeviceType
    ) {
System.out.print("id"+account);
        DeviceEntity device = new DeviceEntity();
        device.setDeviceId(account);
        device.setDeviceBuyer(DeviceBuyer);
        device.setDeviceBuyTime(DeviceBuyTime);
        device.setDevicePlace(DevicePlace);
        device.setDeviceType(DeviceType);
        /*
        *
        *
        * 登记至要前四个
         device.setDeviceValue();
         device.setDeviceAble();
         device.setDeviceNorRent();
        device.setDeviceLastUser();
        /*管理员同意*/
        de.insert(device);
        Map json = new HashMap();
        ResultVO resultVO = new ResultVO();
        json.put("device", device);
        resultVO.setData(json);
        return resultVO;
    }







    /*通过id来更改状态
     * 通常为状态更改接口
     *
     * 默认值可以更改为原数据库里的值 更改defult value
     *
     * */

    @PostMapping(value = "/updateDeviceById")
    public ResultVO updateDeviceById(@RequestParam(value = "DeviceId", required = true, defaultValue = "") int account,
                                     @RequestParam(value = "DeviceBuyer", required = true, defaultValue = "") String DeviceBuyer,
                                     @RequestParam(value = "DeviceBuyTime", required = true, defaultValue = "") String DeviceBuyTime,
                                     @RequestParam(value = "DevicePlace", required = true, defaultValue = "") String DevicePlace,
                                     @RequestParam(value = "DeviceType", required = true, defaultValue = "") String DeviceType) {
        DeviceEntity device = new DeviceEntity();
        device.setDeviceBuyer(DeviceBuyer);
        device.setDeviceBuyTime(DeviceBuyTime);
        device.setDevicePlace(DevicePlace);
        device.setDeviceType(DeviceType);
        device.setDeviceId(account);
        de.updateById(device);
        ResultVO resultVO = new ResultVO();
        Map json = new HashMap();
        json.put("device", device);
        resultVO.setData(json);
        return resultVO;
    }
    @PostMapping (value = "/getTypeDevice")
    public ResultVO getTypeDevice(
                                     @RequestParam(value = "DeviceType", required = true, defaultValue ="") String DeviceType) {
        Map json = new HashMap();
        System.out.print(DeviceType);
        ResultVO resultVO = new ResultVO();
        List<DeviceEntity> list = de.getTypeDevice(DeviceType);




        json.put("deviceTypeList", list);
        resultVO.setData(json);
        /**
         * vedio
         */
        return resultVO;





    }




}